// message_base.h

#ifndef _KS_INC_MESSAGE_BASE_H_
#define _KS_INC_MESSAGE_BASE_H_

#include "types.h"
#include <assert.h>

KS_DECLS_BEGIN

typedef struct _KSMessageBase	KSMessageBase;
typedef struct _KSMessageQueue	KSMessageQueue;

struct _KSMessageBase {
	KSMessageBase*	next;
};

struct _KSMessageQueue {
	KSMessageBase*	head;
	KSMessageBase*	tail;
};

#define ks_message_queue_push_all(queue, other_head, other_tail)	{ \
				assert( (other_tail) && ((other_tail)->next==0) ); \
				if( (queue)->head ) \
					(queue)->tail->next = other_head; \
				else \
					(queue)->head = other_head; \
				(queue)->tail = other_tail; \
			}

#define ks_message_queue_push(queue, msg)	{ \
				assert( (msg) && ((msg)->next==0) ); \
				if( (queue)->head ) \
					(queue)->tail->next = msg; \
				else \
					(queue)->head = msg; \
				(queue)->tail = msg; \
			}

#define ks_message_queue_pop(queue) 	(queue)->head = (queue)->head->next

KS_DECLS_END

#endif//_KS_INC_MESSAGE_BASE_H_

